package com.wgts.wgts.mvp.view.activity.goodsinfo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wgts.wgts.R;
import com.wgts.wgts.base.LazyBaseFragment;
import com.wgts.wgts.localbean.ProductImages;
import com.wgts.wgts.localbean.LocalProductInfo;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class GoodInfoPictureFragment extends LazyBaseFragment {

    Unbinder unbinder;
    @BindView(R.id.recycle_view)
    RecyclerView recycleView;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;

    private static final String IMG_DETAIL = "imgdetail";

    private static final String PRODUCT_INFO = "productInfo";

    private LinearLayoutManager linearLayoutManager;

    private ArrayList<ProductImages> detailImages;

    private LocalProductInfo productInfo;

    @Override
    protected void loadData() {

    }

    @Override
    public void init() {
        detailImages = getArguments().getParcelableArrayList(IMG_DETAIL);
        productInfo = getArguments().getParcelable(PRODUCT_INFO);
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.goods_all_info_fragment, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void initView() {


        refreshLayout.setEnableRefresh(false);
        refreshLayout.setEnableLoadmore(false);



        linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);
        recycleView.setAdapter(new GoodInfoPictureAdapter(getContext(), detailImages, productInfo.productSubtitle));

    }

    public static GoodInfoPictureFragment getInstance(ArrayList<ProductImages> detailImages, LocalProductInfo productInfo){
        GoodInfoPictureFragment fragment = new GoodInfoPictureFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList(IMG_DETAIL, detailImages);
        bundle.putParcelable(PRODUCT_INFO, productInfo);
        fragment.setArguments(bundle);
        return fragment;
    }

}
